package com.enhe.gck.fg;

import com.enhe.gck.communal.PublicConstant;
import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.communal.PublicReturn;
import com.enhe.gck.item.OrderHWANE16677Item;
import com.enhe.gck.item.PouringOrderHWANE18490Item;
import com.enhe.gck.item.SupplyOrderHWANE16829Item;
import com.kuangkie.carbon.panel.CarbonPanel;
import com.kuangkie.carbon.record.FGRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import com.kuangkie.carbon.fg.FuncGroupContext;
import com.kuangkie.carbon.fg.ImproveResultFactory;
import com.kuangkie.carbon.fg.SecondRoundImproveFuncGroup;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import com.enhe.gck.CarbonBaseConstant; //模型Code
import com.enhe.gck.CarbonEnumKeyValue; //枚举字典信息
import com.enhe.gck.CarbonRelationType; //关系类型Code
import com.enhe.gck.item.IcCardHWANE16640Item; // 模型属性Code

import java.util.List;

@Repository(value = "hwane16640366042330866425862")
public class IcCardHWANE16640BNB implements SecondRoundImproveFuncGroup{
	private final Logger logger = LoggerFactory.getLogger(IcCardHWANE16640BNB.class);
	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
			ImproveResultFactory improveResultFactory) {
	}


	/**
	 * 验证IC卡号 是否可用该卡 该卡是否正在使用  可用true 不可用false
	 * @param ic 卡号
	 */
	public boolean verifyCardNumber(ImproveResultFactory improveResultFactory,String code
			,String ic) {
		logger.info("QAQ验证卡号:{}",ic);
		List<String> codeOne = CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.IC卡管理_kgl)
				.getProConJunctionFactory()
				.addEqual(IcCardHWANE16640Item.基本属性组_卡号,ic )
				.goBack().queryCodes();
		if(codeOne==null||codeOne.isEmpty()){
			PublicMethod.returnMessage(improveResultFactory, PublicReturn.IC_1);
			return false;
		}

		List<FGRecord> codes = CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.订单记录_ddjl)
				.getProConJunctionFactory()
				.addEqual(OrderHWANE16677Item.基本属性组_IC卡号, ic)
				.addNotEqual(OrderHWANE16677Item.基本属性组_状态, PublicConstant.OrderStateOver)
				.addEqual(OrderHWANE16677Item.基本属性组_是否退货, CarbonEnumKeyValue.是否_否_f)
				.addEqual(OrderHWANE16677Item.基本属性组_是否作废, CarbonEnumKeyValue.是否_否_f)
				.goBack().queryRecords();
		if(codes!=null && !codes.isEmpty()){
			if(!code.equals(codes.get(0).getRecordCode())){
				PublicMethod.returnMessage(improveResultFactory,PublicReturn.ORDER_51);
				return false;
			}
		}

		List<FGRecord> codes2 = CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.供货订单_ghdd)
				.getProConJunctionFactory()
				.addEqual(SupplyOrderHWANE16829Item.基本属性组_IC卡号, ic)
				.addNotEqual(SupplyOrderHWANE16829Item.基本属性组_状态, PublicConstant.OrderStateOver)
				.addEqual(SupplyOrderHWANE16829Item.基本属性组_是否退货, CarbonEnumKeyValue.是否_否_f)
				.addEqual(SupplyOrderHWANE16829Item.基本属性组_是否作废, CarbonEnumKeyValue.是否_否_f)
				.goBack().queryRecords();
		if(codes2!=null && !codes2.isEmpty()){
			if(!code.equals(codes2.get(0).getRecordCode())){
				PublicMethod.returnMessage(improveResultFactory,PublicReturn.ORDER_52);
				return false;
			}
		}

		List<FGRecord> codes3 = CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.倒料订单_dldd)
				.getProConJunctionFactory()
				.addEqual(PouringOrderHWANE18490Item.基本属性组_IC卡号, ic)
				.addNotEqual(PouringOrderHWANE18490Item.基本属性组_状态, PublicConstant.OrderStateOver)
				.addEqual(PouringOrderHWANE18490Item.基本属性组_是否作废,false)
				.goBack().queryRecords();
		if(codes3!=null && !codes3.isEmpty()){
			if(!code.equals(codes3.get(0).getRecordCode())){
				PublicMethod.returnMessage(improveResultFactory,PublicReturn.ORDER_53);
				return false;
			}
		}

		return true;
	}
}
